/*
 * Created by JFormDesigner on Tue May 24 21:16:05 CST 2022
 */

package jw3.c7.view;

import jw3.c7.controller.Usercontroller;
import jw3.c7.utils.DBConnection;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author Brainrain
 */
public class Cpassword extends JFrame {
    public Cpassword() {
        initComponents();

        this.setVisible(true);
    }

    private void button1MouseClicked(MouseEvent e) {
       String zh=textField1.getText();
       String cpwd=new String(passwordField1.getPassword());
        String sql="UPDATE user SET Pwd=? WHERE zh=?";
            if (zh.equals("")){
                JOptionPane.showMessageDialog(null,"请输入账号和密码");
            }else if (!Usercontroller.wj(zh)){

                JOptionPane.showMessageDialog(null,"该用户不存在");
            }else {
                DBConnection.zsg(sql,new String(passwordField1.getPassword()),textField1.getText());
                JOptionPane.showMessageDialog(null,"修改成功");
            }
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        button1 = new JButton();
        passwordField1 = new JPasswordField();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u8bf7\u8f93\u5165\u8d26\u53f7");
        label1.setForeground(UIManager.getColor("Button.endBackground"));
        contentPane.add(label1);
        label1.setBounds(255, 175, 115, label1.getPreferredSize().height);
        contentPane.add(textField1);
        textField1.setBounds(390, 165, 130, textField1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u8bf7\u8f93\u5165\u4fee\u6539\u540e\u7684\u5bc6\u7801");
        label2.setForeground(UIManager.getColor("Button.endBackground"));
        contentPane.add(label2);
        label2.setBounds(240, 220, 140, 17);

        //---- button1 ----
        button1.setText("\u786e\u5b9a");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(425, 285), button1.getPreferredSize()));
        contentPane.add(passwordField1);
        passwordField1.setBounds(390, 210, 130, passwordField1.getPreferredSize().height);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JButton button1;
    private JPasswordField passwordField1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
